








//
//  NTianbaoSubVC.m
//  nncloud
//
//  Created by macfai on 2018/11/30.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NTianbaoSubVC.h"
#import "NDetailSubCell.h"
#import "NReportSubDetailCell.h"
#import "NReportSubDetailModel.h"
#import "NCaiwuReportSubDetailCell.h"
@interface NTianbaoSubVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)NSArray *titles;

@end

@implementation NTianbaoSubVC
#define cellIdentifier @"reportsub"
#define CaiwuCellIdentifier @"caiwusub"
-(UITableView *)tableView{
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        if ([[NUserModel shareInstance].isIndustryOrFinance containsString:@"财务"]) {
            _tableView.rowHeight = 221.f;
        }else{
            _tableView.rowHeight = 339.f;
        }
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NReportSubDetailCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
         [_tableView registerNib:[UINib nibWithNibName:@"NCaiwuReportSubDetailCell" bundle:nil] forCellReuseIdentifier:CaiwuCellIdentifier];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = kWhiteColor;
    self.dataArray = [NSMutableArray array];
    if (_atitle) {
        [self.navigationItem setItemWithTitle:_atitle textColor:kNavigationTitleColor fontSize:18 itemType:center];
    }
    [self.view addSubview:self.tableView];
    
    [self loadData];
    // Do any additional setup after loading the view.
}

- (void)loadData {
    
    NSDictionary *dic = @{@"id":self.IndustryId,@"type":self.type,@"size":@(10),@"curPage":@(1)};
    NSString *url;
    if ([[NUserModel shareInstance].isIndustryOrFinance containsString:@"财务"]) {
        
        url = kCaiwuSubDetailUrl;
    }else{
        
        url =ksubDetailUrl;
    }
    [[NNRCNetRequest manager] getWithUrl:url params:dic success:^(id result) {
        
        YYLog(@"%@",result);
        WeakStament(ws);
        
        if ([[result objectForKey:@"code"] integerValue] == 0) {
            NSArray *arr = result[@"page"][@"records"];
            YYLog(@"%@",arr);
            
            for (NSDictionary *dict in arr) {
                NReportSubDetailModel *model = [NReportSubDetailModel mj_objectWithKeyValues:dict];
                [ws.dataArray addObject:model];
            }
            
            [ws.tableView reloadData];
        }else{
            
            [AFToast showText:result[@"msg"]];
        }
    } failure:^(id failure) {
        YYLog(@"%@",failure);
    }];
}
#pragma mark - datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  self.dataArray.count;
//    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([[NUserModel shareInstance].isIndustryOrFinance containsString:@"财务"]) {
        
        NCaiwuReportSubDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CaiwuCellIdentifier forIndexPath:indexPath];
        NReportSubDetailModel *model = self.dataArray[indexPath.section];
        cell.model = model;
        return cell;
        
    }else{
        
        NReportSubDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        
        NReportSubDetailModel *model = self.dataArray[indexPath.section];
        cell.model = model;
        return cell;
    }
    
    return nil;
}

#define SectionTitleHeaderHeight 0
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SectionTitleHeaderHeight;//如果设置section的header高度，不设置footer高度，footer默认等于header高度
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, SectionTitleHeaderHeight)];
//    view.backgroundColor = kBackgroundColor;
//    return view;
    return nil;
}
@end
